package com.sharkpro.designPattern.myAdapter;

import cn.hutool.core.io.FileUtil;

import java.io.BufferedOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

/**
 * @author jianxin.wei
 * @description
 * @date 2024/12/17 15:56
 */
public class FileProperties extends Properties implements FileIO {

    private static FileReader fileReader;
    private static FileWriter fileWriter;
    private static Properties properties = new Properties();

    @Override
    public void readFromFile(String fileName) throws IOException {
        this.fileReader = new FileReader(fileName);
        properties.load(this.fileReader);
    }

    @Override
    public void writeToFile(String fileName) throws IOException {
        this.fileWriter=new FileWriter(fileName);
        properties.store(this.fileWriter,null);
        this.fileWriter.flush();
        this.fileWriter.close();
    }

    @Override
    public void setValue(String key, String value) {
        properties.setProperty(key,value);
    }

    @Override
    public String getValue(String key) {
        return properties.getProperty(key);
    }
}
